/*
 * Copyright (c) 2014-2016 Alibaba Group. All rights reserved.
 * License-Identifier: Apache-2.0
 *
 * Licensed under the Apache License, Version 2.0 (the "License"); you may
 * not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *    http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 */

package com.yisoo.ubag.iot.aliyun.client;

import com.aliyuncs.DefaultAcsClient;
import com.aliyuncs.profile.DefaultProfile;
import com.aliyuncs.profile.IClientProfile;
import com.yisoo.ubag.iot.aliyun.util.LogUtil;

import java.util.Properties;

public class IotClient {
	private static String accessKeyID = "LTAI4GJsxqB4enkdqv5VievY";
	private static String accessKeySecret = "NVhn0K3qBRsiC2KuQDnQtlnxI4Lacv";
	private static String regionId = "cn-shanghai";
    private static String domain = "iot.cn-shanghai.aliyuncs.com";
    private static String version = "2018-01-20";



    public static DefaultAcsClient getClient() {
		DefaultAcsClient client = null;

//		Properties prop = new Properties();
		try {
//			prop.load(Object.class.getResourceAsStream("/config.properties"));
//            System.out.println("配置文件"+prop);
//            System.out.println("配置文件测试"+accessKeyID);
//			accessKeyID = prop.getProperty("user.accessKeyID");
//			accessKeySecret = prop.getProperty("user.accessKeySecret");
//			regionId = prop.getProperty("iot.regionId");
//            domain = prop.getProperty("iot.domain");
//            version = prop.getProperty("iot.version");
//# ak
//            user.accessKeyID = LTAI4GJsxqB4enkdqv5VievY
//# sk
//            user.accessKeySecret =NVhn0K3qBRsiC2KuQDnQtlnxI4Lacv
//# 要访问的iot的regionId 目前支持的 cn-shanghai(华东2)、ap-southeast-1（新加坡） 、us-west-1（美西）
//            iot.regionId = cn-shanghai
//#iot套件对应的产品code 保持不变即可
//            iot.productCode = Iot
//#Iot api的服务地址 跟regionId对应 这是华东2的
//            iot.domain = iot.cn-shanghai.aliyuncs.com
//#Iot api 的版本
//            iot.version = 2018-01-20
//			IClientProfile profile = DefaultProfile.getProfile(regionId, accessKeyID, accessKeySecret);
//			DefaultProfile.addEndpoint(regionId, regionId, prop.getProperty("iot.productCode"),
//					prop.getProperty("iot.domain"));
			IClientProfile profile = DefaultProfile.getProfile(regionId, accessKeyID, accessKeySecret);
			DefaultProfile.addEndpoint(regionId, regionId, "Iot",
                    domain);
			// 初始化client
			client = new DefaultAcsClient(profile);

		} catch (Exception e) {
			LogUtil.print("初始化client失败！exception:" + e.getMessage());
		}

		return client;
	}

    public static String getRegionId() {
        return regionId;
    }

    public static void setRegionId(String regionId) {
        IotClient.regionId = regionId;
    }

    public static String getDomain() {
        return domain;
    }

    public static void setDomain(String domain) {
        IotClient.domain = domain;
    }

    public static String getVersion() {
        return version;
    }

    public static void setVersion(String version) {
        IotClient.version = version;
    }
}
